﻿using Microsoft.Extensions.Logging;
using System;

namespace FileWatchService.Bll
{
    public class FileDataChangeBll
    {
        private readonly ILogger<FileDataChangeBll> logger;
        public FileDataChangeBll(ILogger<FileDataChangeBll> logger)
        {
            this.logger = logger;
        }
        public void OnFileChanged(object sender, System.IO.FileSystemEventArgs e)
        {
            try
            {
                logger.LogInformation($"{e.ChangeType}:{e.FullPath}");
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "处理文件变化错误");
            }
        }
        public void OnFileRenamed(object sender, System.IO.RenamedEventArgs e)
        {
            try
            {
                logger.LogInformation($"{e.ChangeType}:{e.OldName} to {e.FullPath}");
            }
            catch (Exception ex)
            {
                logger.LogError(ex, "处理文件变化错误");
            }
        }
    }
}
